import 'dart:ui';

import 'package:flutter/material.dart';

class LayoutItem {
  Rect rect;
  double rotation;

  LayoutItem({
    double top = 0,
    double left = 0,
    // double bottom,
    // double right,
    double width = 0,
    double height = 0,
    Rect rect,
    this.rotation = 0,
  }) : this.rect = rect ?? Rect.fromLTWH(left, top, width, height);

  static LayoutItem lerp(LayoutItem a, LayoutItem b, double t) {
    assert(t != null);
    if (a == null && b == null) return null;
    // if (a == null)
    //   return Rect.fromLTRB(b.left * t, b.top * t, b.right * t, b.bottom * t);
    // if (b == null) {
    //   final double k = 1.0 - t;
    //   return Rect.fromLTRB(a.left * k, a.top * k, a.right * k, a.bottom * k);
    // }
    return LayoutItem(
      rect: Rect.lerp(a.rect, b.rect, t),
      rotation: lerpDouble(a.rotation, b.rotation, t),
    );
  }
}

class LayoutItemTween extends Tween<LayoutItem> {
  LayoutItemTween({LayoutItem begin, LayoutItem end})
      : super(
          begin: begin,
          end: end,
        );

  @override
  LayoutItem lerp(double t) => LayoutItem.lerp(begin, end, t);
}
